package leetcode.code1805;

import java.util.HashSet;
import java.util.Set;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public int numDifferentIntegers2(String word) {
		char[] cs = word.toCharArray();
		int cnt = 0;
		int len = cs.length;
		boolean num = false;
		for (int i = 0; i < len; i++) {
			char c = cs[i];
			if (c >= '0' && c <= '9') {
				num = true;
			} else if (num) {
				cnt++;
				num = false;
			}
		}
		if (cs[len - 1] >= '0' && cs[len - 1] <= '9') {
			cnt++;
		}
		return cnt;
	}

	public int numDifferentIntegers(String word) {
		char[] cs = word.toCharArray();
		Set<String> set = new HashSet<>();
		int len = cs.length;
		boolean num = false;
		StringBuffer sb = new StringBuffer();
		char c = 1;
		for (int i = 0; i <= len; i++) {
			if (i < len && (c = cs[i]) >= '0' && c <= '9') {
				if (sb.length() != 0 || c != '0') {
					sb.append(c);
				}
				num = true;
			} else if (num) {
				if (sb.length() == 0) {
					set.add("0");
				} else {
					set.add(sb.toString());
				}
				sb = new StringBuffer();
				num = false;
			}
		}
		return set.size();
	}

	@Override
	public void debug4() {
		HelpDebug.compare(2, this.numDifferentIntegers("035985750011523523129774573439111590559325a1554234973"));
		HelpDebug.compare(1, this.numDifferentIntegers("a1b01c001"));
		HelpDebug.compare(2, this.numDifferentIntegers("a1b0c00"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
